package com.wocao.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wocao.entity.ReqBody;
import com.wocao.entity.SysRole;
import com.wocao.entity.ZyCommunity;
import com.wocao.entity.ZyComplaintSuggest;
import com.wocao.mapper.ZyComplaintSuggestMapper;
import com.wocao.service.ZyComplaintSuggestService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wocao.utils.ExcelUtil;
import com.wocao.utils.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 投诉建议  服务实现类
 * </p>
 *
 * @author cwj
 * @since 2023-11-29
 */
@Service
public class ZyComplaintSuggestServiceImpl extends ServiceImpl<ZyComplaintSuggestMapper, ZyComplaintSuggest> implements ZyComplaintSuggestService {

    @Autowired
    private ZyComplaintSuggestMapper zyComplaintSuggestMapper;

    @Override
    public Page<ZyComplaintSuggest> selectComplaintAll(Page page, ReqBody reqBody) {
        return zyComplaintSuggestMapper.selectComplaintAll(page,reqBody.getComplaintType());
    }

    @Override
    public void derive(HttpServletResponse response, String[] complaintIds) throws IOException {
        List<ZyComplaintSuggest> zyComplaintSuggestList = new ArrayList<>();
        for (int i = 0; i < complaintIds.length; i++) {
            ZyComplaintSuggest suggest = zyComplaintSuggestMapper.selectById(complaintIds[i]);
            zyComplaintSuggestList.add(suggest);
        }
        ExcelUtil.export(response,ZyComplaintSuggest.class,zyComplaintSuggestList);
    }

    @Override
    public void editComplaintStatus(String comId) {
        zyComplaintSuggestMapper.editComplaintStatus(comId);
    }

    @Override
    public List<ZyComplaintSuggest> selectAllByOwnerId(String userId,String comType) {
        return zyComplaintSuggestMapper.selectAllByOwnerId(userId,comType);
    }

    @Override
    public void ComplaintAdd(ZyComplaintSuggest zyComplaintSuggest) {
        zyComplaintSuggest.setCreateTime(LocalDateTime.now());
        zyComplaintSuggest.setComplaintStatus("0");
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(8, 1);
        Long nextId = idWorker.nextId();
        zyComplaintSuggest.setComplaintSuggestId(nextId+"");
        zyComplaintSuggestMapper.insert(zyComplaintSuggest);
    }
}
